<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="ctx" scope="page" value="${request.contextPath}" />
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE  >
<html >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>报修单详情</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/static/weui/1.1.2/weui-for-work.min.css"/>
    <script type="text/javascript" src="${ctx}/static/jquery/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="${ctx}/static/weui/1.1.2/weui.min.js"></script>
    <!-- 企业微信的JS-SDK -->
    <%--<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>--%>
    <style>
        select,option{
            height: 22px;
            width: 150px;
            /*text-align-last: right;*/
            border-radius: 5px;
            font-size: .95em;
            color: #999;
        }
        textarea{
            font-size: .95em;
            height: 47px;
            width: 166px;
        }
    </style>
</head>
<body style="background-color: #f8f8f8" >
<div class="page">
<div class="page__bd">
    <form id = "repaireForm" action="${ctx}/weixin/repaire/update" method="post" enctype="multipart/form-data">
    <input type="hidden" name="userId" id="userId" value="${userId}"/>
    <input type="hidden" name="id" value="${repaireInfo.id}"/>
    <div class="weui-form-preview">
        <div class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">报修人</label>
                <span class="weui-form-preview__value"><c:out value="${repaireInfo.creatorName}"/></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">公司名</label>
                <span class="weui-form-preview__value"><c:out value="${repaireInfo.callerCompanyName}"/></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">部门</label>
                <span class="weui-form-preview__value"><c:out value="${repaireInfo.callerDeptName}"/></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">地址</label>
                <span class="weui-form-preview__value"><c:out value="${repaireInfo.address}"/></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">选项</label>
                <span class="weui-form-preview__value">&nbsp
                    <select name="machineType" onchange="changePicWords(this)">
                        <c:forEach items="${picWords}" var="picWord">
                            <c:if test="${picWord.words==repaireInfo.machineType}">
                                <script>$(function(){changePicWords("${picWord.pagePosition}")});</script>
                                <option selected value="${picWord.id}">${picWord.words}</option>
                            </c:if>
                            <c:if test="${picWord.words!=repaireInfo.machineType}">
                                <option value="${picWord.id}">${picWord.words}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">判断常用</label>
                <span class="weui-form-preview__value">
                    <select id="normal" name="repaireSubject"></select>
                </span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">备注</label>
                <span class="weui-form-preview__value">
                    <textarea name="description"><c:out value="${repaireInfo.description}"/></textarea>
                </span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">创建时间</label>
                <span class="weui-form-preview__value"><fmt:formatDate pattern="yyyy-MM-dd HH:mm" value="${repaireInfo.createTime}" type="both" /></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">服务时间</label>
                <span class="weui-form-preview__value"><c:out value="${repaireInfo.expectTime}"/></span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">计时</label>
                <span style="color: red" class="weui-form-preview__value" id="timer">00:00:00</span>
            </div>
        </div>
    </div>
    <br>
    </form>
</div>
</div>

<div id="toast" style="display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-icon-warn weui-icon_toast"></i>
        <p class="weui-toast__content"></p>
    </div>
</div>

<div id="toast_success" style="display: none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-icon-success-no-circle weui-icon_toast"></i>
        <p class="weui-toast__content"></p>
    </div>
</div>
<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary"  href="#" onclick="javascript:submitRepaireInfo()" id="showTooltips">确定</a>
</div>
<script type="text/javascript" src="${ctx}/static/weixin/allocation_repaire.js" ></script>
<script>

    $(function () {
        timer = setInterval("startTimer()", 1000);

    });
    var seconds = ${seconds};
    function startTimer() {
        var minuteStr, secondStr ,hourStr;
        var hour = parseInt(seconds / 3600);
        var remainderHour = seconds % 3600;
        if(hour <10){
            hourStr = "0" + hour;
        }else {
            hourStr =  hour;
        }
        var minute = parseInt(remainderHour / 60);
        var remainder = remainderHour % 60;
        if(minute < 10){
            minuteStr = "0" + minute;
        } else {
            minuteStr = minute;
        }

        if(remainder < 10){
            secondStr = "0" + remainder;
        } else {
            secondStr = remainder;
        }

        $("#timer").html(hourStr+ ":" +minuteStr + ":" + secondStr);
        seconds++;
    }

    function changePicWords(pagePosition) {
        if(typeof pagePosition != "string")
            pagePosition=$(pagePosition).val();
        $.ajax({
            url: "${ctx}/weixin/picWord/normalPicWords",
            data:{code:'1',parentPosition:pagePosition},
            dataType: "json",
            type:"post",
            success:function(result){
                if(result.code=='0'){
                    $("#normal").html("");
                    var normals= result.data;
                    var normalHtml
                    $.each(normals,function (index,picWord) {
                        if(picWord.words == "${repaireInfo.repaireSubject}")
                            normalHtml=normalHtml+"<option selected value="+picWord.id+">"+picWord.words+"</option>";
                        else
                            normalHtml=normalHtml+"<option value="+picWord.id+">"+picWord.words+"</option>";
                    });
                    $("#normal").html(normalHtml);
                }else{
                    showErrorToast(result.msg);
                }
            }
        });
    }
    var checkSubmitFlg = true;
    function submitRepaireInfo() {
        if (checkSubmitFlg == true) {
            checkSubmitFlg = false;
            var repaireForm = $("#repaireForm");
            var url = repaireForm.attr("action");
            var submitData = repaireForm.serialize();
            $.ajax({
                url: url,
                data: submitData,
                dataType: 'json',
                success: function () {
                    document.location.href = "/weixin/engineer/beginServer/" + $("[name=id]").val();
                }
            });
        }
    }
</script>
</body>
</html>
